package com.cg.service;

import com.cg.mapper.EventcategorieMapper;
import com.cg.mapper.UserMapper;
import com.cg.pojo.entity.Eventcategorie;
import com.cg.pojo.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EventcategorieService {
    @Autowired
    EventcategorieMapper eventcategorieMapper;


    @Autowired
    UserMapper userMapper;
    public List<Eventcategorie> getAll(Integer userId) {

        return eventcategorieMapper.selectEventcategorieByUserId(userId);
    }
    public Eventcategorie getById(Integer categoryId) {
        return eventcategorieMapper.getById(categoryId);
    }
    public void add(Eventcategorie eventcategorie) {
        UserEntity user = userMapper.selectByUsername(eventcategorie.getUsername());
        eventcategorie.setUserId(user.getId());
        eventcategorieMapper.add(eventcategorie);
    }

    public void update(Eventcategorie eventcategorie) {
        eventcategorieMapper.update(eventcategorie);
    }

    public void delete(Integer categoryId) {
        eventcategorieMapper.delete(categoryId);
    }
}